//职位修改事件
function xiugai() {
	let tbs = event.target.parentNode.parentNode.getElementsByTagName('td');
	let inp = $('#zwxg .form-control');
	for(var i = 0; i < inp.length - 1; i++) {
		$(inp[i]).val(tbs[i].innerHTML);
	}
	let str = '';
	if(tbs[inp.length - 1].innerHTML == '<input type="button" class="btn btn-info btn-xs" value="启用">') {
		str = 'qiyong';
	} else if(tbs[inp.length - 1].innerHTML == '<input type="button" class="btn btn-danger btn-xs" value="禁用">') {
		str = 'jinyong';
	} else {
		str = tbs[inp.length - 1].innerHTML;
	}
	$(inp[i]).val(str);
	$('#zwxg').modal();
}
$(function() {
	//折叠菜单的显示触发的事件
	$('.zhediecaidan').on('show.bs.collapse', function() {
		this.parentNode.firstElementChild.firstElementChild.firstElementChild.className = "glyphicon glyphicon-menu-down";
	});
	//折叠菜单的隐藏触发的事件
	$('.zhediecaidan').on('hide.bs.collapse', function() {
		this.parentNode.firstElementChild.firstElementChild.firstElementChild.className = "glyphicon glyphicon-menu-right";
	});
	//所有主多选框点击产生的事件 --让下边的多选框进行级联
	$('.zhu').click(function() {
		if(this.className == 'glyphicon glyphicon-check zhu') {
			this.className = 'glyphicon glyphicon-unchecked zhu';
		} else {
			this.className = 'glyphicon glyphicon-check zhu';
		}
		let inp = this.parentNode.parentNode.parentNode.lastElementChild.firstElementChild.getElementsByTagName('span');
		for(let i = 0; i < inp.length; i++) {
			if(this.className == 'glyphicon glyphicon-check zhu') {
				inp[i].className = 'glyphicon glyphicon-check ge';
			} else {
				inp[i].className = 'glyphicon glyphicon-unchecked ge';
			}
		}
	});
	//所有子多选框选中之后对父级多选框级联
	$('.ge').click(function() {
		if(this.className == 'glyphicon glyphicon-check ge') {
			this.className = 'glyphicon glyphicon-unchecked ge';
		} else {
			this.className = 'glyphicon glyphicon-check ge';
		}
		let zhu = this.parentNode.parentNode.parentNode.parentNode.firstElementChild.getElementsByClassName('zhu')[0];
		let ge = this.parentNode.parentNode.getElementsByClassName('ge');
		let asd = false;
		$(ge).each(function() {
			if(this.className == 'glyphicon glyphicon-check ge') {
				asd = true;
				return false;
			}
		});
		if(asd) {
			zhu.className = 'glyphicon glyphicon-check zhu';
		} else {
			zhu.className = 'glyphicon glyphicon-unchecked zhu';
		}
	});
	//提示信息框的弹出以及隐藏
	$('.queren').click(function() {
		let tbs = $('#tb td')
		let inp = $('#zwxg .form-control');
		for(var i = 0; i < inp.length; i++) {
			let str = '';
			if(inp[i].value == 'qiyong') {
				str = '<input type="button" class="btn btn-info btn-xs" value="启用">';
			} else if(inp[i].value == 'jinyong') {
				str = '<input type="button" class="btn btn-danger btn-xs" value="禁用">';
			} else {
				str = inp[i].value;
			}
			tbs[i].innerHTML = str;
		}
		toastr.success('操作成功');
	});

	//职位修改输入框监听 事件
	$('#zwxg .form-control').each(function() {
		$(this).on('input porpertychange', function() {
			if($(this).val() == "") {
				this.parentNode.className = 'input-group col-sm-12 has-error';
				this.parentNode.getElementsByClassName('glyphicon')[0].className = 'glyphicon form-control-feedback glyphicon-remove';
			} else {
				this.parentNode.className = 'input-group col-sm-12 has-success';
				this.parentNode.getElementsByClassName('glyphicon')[0].className = 'glyphicon form-control-feedback glyphicon-ok';
			}
		})
	})
	//新增职位输入框监听 事件
	$('#xzzw .form-control').each(function() {
		$(this).on('input porpertychange', function() {
			if($(this).val() == "") {
				this.parentNode.className = 'input-group col-sm-12 has-error';
				this.parentNode.getElementsByClassName('glyphicon')[0].className = 'glyphicon form-control-feedback glyphicon-remove';
			} else {
				this.parentNode.className = 'input-group col-sm-12 has-success';
				this.parentNode.getElementsByClassName('glyphicon')[0].className = 'glyphicon form-control-feedback glyphicon-ok';
			}
		})
	})
})